﻿// =================================================================== 
// 项目说明
//====================================================================
// lsc @Copy Right 2019
// 文件： CustomerCardContentRepository.cs
// 项目名称：斑马车务
// 创建时间：2019/10/14
// 负责人：lsc
// ===================================================================
using System;
using System.Text;
using System.Collections.Generic;
using YouWei.Infrastructure.Entity;
using YouWei.Infrastructure.Models;
using Dapper;
using Dapper.Extensions;

namespace YouWei.Infrastructure.Repository
{
	/// <summary>
	/// 仓储层
	/// </summary>	
	public class UserCardContentRepository:BaseRepository<UserCardContent>
	{		
    
        #region 构造

        public UserCardContentRepository() : base(){}

        public UserCardContentRepository(string connectionString) : base(connectionString){}

        public UserCardContentRepository(DatabaseContext dbContext) : base(dbContext){}

        #endregion

        /// <summary>
        /// 分页查询，带条件
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        public Page<UserCardContentDto> GetPages(int pageIndex, long pageSize, ReqUserCardContentCondition condition)
        {
            StringBuilder sql = new StringBuilder("SELECT * FROM UserCardContent WITH(NOLOCK) where IsActive =1");
            if (!string.IsNullOrWhiteSpace(condition.StartDate))
            {
                sql.Append(" AND CreatedDate>@StartDate");
            }
            if (!string.IsNullOrWhiteSpace(condition.EndDate))
            {
                sql.Append(" AND CreatedDate<@EndDate");
            }
            if (!string.IsNullOrWhiteSpace(condition.Name))
            {
                sql.Append(" AND CHARINDEX(@Name,Name) >0");
            }
       

            DynamicParameters dparams = new DynamicParameters();
            dparams.Add("@Name", condition.Name, System.Data.DbType.String);
            dparams.Add("@StartDate", condition.StartDate, System.Data.DbType.String);
            dparams.Add("@EndDate", condition.EndDate, System.Data.DbType.String);
            return dbContext.Connection.Page<UserCardContentDto>(pageIndex, pageSize, sql.ToString(), dparams);
        }

        /// <summary>
        /// 获取客户卡内容项列表
        /// </summary>
        /// <returns></returns>
        public List<UserCardContent> GetList()
        {
            string sql = "SELECT * FROM UserCardContent WITH(NOLOCK) where IsActive =1";
            return Query(sql);
        }
    }
}